package com.ipfsemc.ipfsemc.wx.menu;

import org.springframework.stereotype.Component;
import org.weixin4j.model.message.Articles;
import org.weixin4j.model.message.OutputMessage;
import org.weixin4j.model.message.event.*;
import org.weixin4j.model.message.output.NewsOutputMessage;
import org.weixin4j.model.message.output.TextOutputMessage;
import org.weixin4j.spi.IEventMessageHandler;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义事件消息处理器
 *
 * @author yangqisheng
 */
@Component
public class MyAtsEventMessageHandler implements IEventMessageHandler {

    @Override
    public OutputMessage subscribe(SubscribeEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("感谢您的关注！");
        return out;
    }

    @Override
    public OutputMessage unSubscribe(UnSubscribeEventMessage msg) {
        //取消关注
        return null;
    }

    @Override
    public OutputMessage qrsceneSubscribe(QrsceneSubscribeEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("感谢您的关注！，来源：" + msg.getEventKey());
        return out;
    }

    @Override
    public OutputMessage qrsceneScan(QrsceneScanEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("你的消息已经收到！A");
        return out;
    }

    @Override
    public OutputMessage location(LocationEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("你的消息已经收到！B");
        return out;
    }

    @Override
    public OutputMessage click(ClickEventMessage msg) {
        String eventKey = msg.getEventKey();
        TextOutputMessage out=null;
        if (eventKey.equals("101")){
            NewsOutputMessage outputMessage=new NewsOutputMessage();
            List<Articles> list=new ArrayList<>();


            Articles articles=new Articles();
            articles.setTitle("");
            articles.setPicUrl("https://mmbiz.qpic.cn/mmbiz_jpg/9sQH25udFRYqtojGjFiaIU74d8Q6LrwFv7iboiasXJ39vSB69GAvsLBn0BNHOI7ufKVh8rebmw5grCibpbNpXpFjjA/0?wx_fmt=jpeg");
            articles.setUrl("https://mp.weixin.qq.com/s/MH6LEYHyTZMHBExbjmnClA");
            articles.setDescription("科普IPFS&FIL的工作原理、投资价值、参与方式、投资收益、投资风险以及IPFS易迈云相关。");

            Articles a2=new Articles();
            a2.setDescription("");
            a2.setTitle("IPFS超级存储革命-Filecoin科普访谈");
            a2.setPicUrl("");
            a2.setUrl("https://mp.weixin.qq.com/s/MH6LEYHyTZMHBExbjmnClA");

            list.add(articles);
            list.add(a2);

            outputMessage.setArticles(list);
            return outputMessage;
        }else if (eventKey.equals("103")){
            out = new TextOutputMessage();
            out.setContent("敬请期待！");
        }

        return out;
    }

    @Override
    public OutputMessage view(ViewEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("点击了链接！D");
        return out;
    }

    @Override
    public OutputMessage scanCodePush(ScanCodePushEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("扫码！E");
        return out;
    }

    @Override
    public OutputMessage scanCodeWaitMsg(ScanCodeWaitMsgEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("扫码等待中！F");
        return out;
    }

    @Override
    public OutputMessage picSysPhoto(PicSysPhotoEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("发起拍照！G");
        return out;
    }

    @Override
    public OutputMessage picPhotoOrAlbum(PicPhotoOrAlbumEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("选择相册！H");
        return out;
    }

    @Override
    public OutputMessage picWeixin(PicWeixinEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("上次图片！I");
        return out;
    }

    @Override
    public OutputMessage locationSelect(LocationSelectEventMessage msg) {
        TextOutputMessage out = new TextOutputMessage();
        out.setContent("选择地理位置！J");
        return out;
    }

}
